package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("管理端")
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
@Slf4j
public class CategoryController {

    @Autowired
    public CategoryService categoryService;

    /**
     * 菜品分类分页查询
     *
     * @param categoryPageQueryDTO
     * @return
     */
    @ApiOperation(value = "菜品分类分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("员工分页查询，参数为：{}", categoryPageQueryDTO);
        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);//后续定义
        return Result.success(pageResult);
    }

    /**
     *新增分类
     *
     * @param categoryDTO
     * @return
     */
    @ApiOperation(value = "新增分类")
    @PostMapping
    public Result<String> add(@RequestBody CategoryDTO categoryDTO){
        log.info("新增分类信息: {}", categoryDTO);
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }

    /**
     *
     * @param status
     * @param id
     * @return
     */
    @ApiOperation("启用禁用分类")
    @PostMapping("/status/{status}")
    public Result<Object> startOrStop(@PathVariable Integer status, long id){
        log.info("启用禁用分类id: {}", id);
        categoryService.startOrStop(status, id);
        return Result.success();
    }

    /**
     * 修改分类信息
     *
     * @param category
     * @return
     */
    @ApiOperation("修改分类信息")
    @PutMapping
    public Result<Object> editEmployeeMessage(@RequestBody Category category){
        log.info("修改分类信息: {}", category);
        categoryService.edit(category);
        return Result.success();
    }

    /**
     * 删除分类
     *
     * @param id
     * @return
     */
    @ApiOperation("删除分类")
    @DeleteMapping
    public Result<Object> deleteCategory(long id){
        categoryService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<Category>> getByType(Integer type){
        List<Category>  categorys = categoryService.getByType(type);
        return Result.success(categorys);
    }
}
